package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.poi.ExcelUtil;
import com.project.domain.bo.MiddleCheckOrCompleteBo;
import com.project.domain.entity.BizProjectComplete;
import com.project.domain.vo.BizProjectCompleteVo;
import com.project.service.ICompleteProService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 项目结项
 */

@Api(tags = "项目结项")
@RestController
@RequestMapping("/pro/complete")
public class CompleteProController extends BaseController {

    @Autowired
    private ICompleteProService completeProService;

    @ApiOperation("列表左上方统计")
    @GetMapping("/groups")
    public AjaxResult groups(MiddleCheckOrCompleteBo bizProjectComplete){
        return success(completeProService.selectGroups(bizProjectComplete));
    }

    /**
     * 查询项目结项列表
     */
    @ApiOperation("项目结项列表")
    @GetMapping("/list")
    public TableDataInfo list(MiddleCheckOrCompleteBo bizProjectComplete)
    {
        IPage<BizProjectCompleteVo> list = completeProService.selectBizProjectCompleteList(bizProjectComplete,"select");
        return TableDataInfo.build(list.getRecords(),list.getTotal());
    }

    /**
     * 导出项目结项列表
     */
    @Log(title = "项目结项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody MiddleCheckOrCompleteBo bizProjectComplete)
    {
        IPage<BizProjectCompleteVo> list = completeProService.selectBizProjectCompleteList(bizProjectComplete,"export");
        ExcelUtil<BizProjectCompleteVo> util = new ExcelUtil<BizProjectCompleteVo>(BizProjectCompleteVo.class);
        util.showColumn(bizProjectComplete.getExportStr().split(","));
        util.exportExcelByOrder(response, list.getRecords(), "项目结项数据",bizProjectComplete.getExportStr().split(","));
    }

    /**
     * 获取项目结项详细信息
     */
    @ApiOperation("获取项目结项详细信息")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID)
    {
        return success(completeProService.selectBizProjectCompleteByID(ID));
    }

    /**
     * 新增项目结项
     */
    @ApiOperation("新增项目结项")
    @Log(title = "项目结项", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizProjectComplete bizProjectComplete)
    {
        return completeProService.saveBizProjectComplete(bizProjectComplete,"add");
    }

    /**
     * 修改项目结项
     */
    @ApiOperation("修改项目结项")
    @Log(title = "项目结项", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizProjectComplete bizProjectComplete)
    {
        return completeProService.saveBizProjectComplete(bizProjectComplete,"edit");
    }

    /**
     * 删除项目结项
     */
    @ApiOperation("删除项目结项")
    @Log(title = "项目结项", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable String[] IDs)
    {
        return toAjax(completeProService.deleteBizProjectCompleteByIDs(IDs));
    }
}
